package com.haisen.dataobject.query;

import com.haisen.core.utils.BaseQuery;
import com.haisen.core.utils.DateUtil;
import com.haisen.dataobject.entity.Rank;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
@Slf4j
public class RankQuery extends BaseQuery<Rank> {

    private String searchDate;
    private String username;


    /**
     * 转换后的开始日期和结束日期
     */
    private String beginDate;
    private String endDate;

    public String getSearchDate() {
        return searchDate;
    }

    public void setSearchDate(String searchDate) {
        String[] dateArr = searchDate.split(" - ");
        //log.info("解析日期范围={}", JSON.toJSONString(dateArr));
        if (dateArr.length >1) {
            SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
            Date beg = new Date();
            Date end = new Date();
            try {
                beg = sdf.parse(dateArr[0]);
                end = sdf.parse(dateArr[1]);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            beginDate = DateUtil.toDateTimeString(beg, "yyyy-MM-dd");
            endDate = DateUtil.toDateTimeString(end, "yyyy-MM-dd");
        }
        this.searchDate = searchDate;
    }

}
